package io.renren.wechat.authen.service.impl;

import io.renren.wechat.authen.common.Constant;
import io.renren.wechat.authen.dao.LoginDao;
import io.renren.wechat.authen.entity.JsapiTicket;
import io.renren.wechat.authen.service.LoginService;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2018/3/19 0019.
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    LoginDao loginDao;

    public String findUserIdByOpenId(String openId){
        return  loginDao.findUserIdByOpenId(openId);
    }
    public void insertWecharData(String username,String openId){
        loginDao.insertWecharData(username,openId);
    }

    @Override
    public JsapiTicket getJsapiTicket(String accessToken) throws WxErrorException {

        JsapiTicket ticket=new JsapiTicket();
        String requestUrl = Constant.js_api_ticket_url;
//        JSONObject jsonObject =WeixinUtil.httpRequest(requestUrl, "GET", null);
//
//
//            ticket.setTicket(jsonObject.getString("ticket"));
          //  ticket.setExpiresIn(jsonObject.getString("expires_in"));
        return ticket;
    }
}
